package com.wodsy.phoenix.apps.pay.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.wodsy.phoenix.dataobject.payc.vo.PayOrderReq;
import com.wodsy.phoenix.dataservice.payc.service.PayService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jiwenku on 2015/5/19.
 * 支付控制器
 */
@Controller
@RequestMapping("pay")
public class PayController {
    private static final Log logger = LogFactory.getLog(PayController.class);
    @Reference(interfaceClass = PayService.class,interfaceName="com.wodsy.phoenix.dataservice.payc.service.PayService")
    private PayService payService;

    /**
     * 跳转到选择支付方式页面
     * @param orderNos 要支付的订单号，多个订单号已逗号分开
     * @return
     */
    @RequestMapping("choosePayChannel")
    public String choosePayChannel(String orderNos, Model model) {
        //验证登陆

        //查询订单信息，主要是订单总价

        model.addAttribute("orderNos",orderNos);
        model.addAttribute("orderMoney",100);
        return "pay/pay";
    }
    /**
     * 查询订单详情
     * @param orderNos 要支付的订单号，多个订单号已逗号分开
     * @return
     */
    @RequestMapping("getOrderInfo")
    @ResponseBody
    public List getOrderInfo(String orderNos, Model model) {
        //查询订单信息

        ArrayList list = null;

        return list;
    }

    /**
     * 确认支付到第三方支付页面
     * @param payOrderReq
     * @return
     */
    @RequestMapping("payOrder")
    public String payOrder(PayOrderReq payOrderReq,Model model) {

        //验证登陆
        payOrderReq.setOrderNos("1111");
        payOrderReq.setPayChannel(2);
        payOrderReq.setPayBlank("ali");

        //校验支付方式
        if (payOrderReq.getPayChannel()==0)
        {
            logger.info("没有选择支付方式");

        }
        if (payOrderReq.getPayBlank()==null||payOrderReq.getPayBlank().equals(""))
        {
            logger.info("没有选择支付银行");

        }

        String payInfo = payService.saveOrderPayMoneyPartnerTrade(payOrderReq);
        logger.info(payInfo);
        model.addAttribute("sHtmlText",payInfo);

        return  "pay/payapi";
    }
}
